/**
 * ----------------------------------------------------------------------------
 * Copyright Jens Konopka
 * 
 * Alle Rechte vorbehalten.
 * Licence: Apache 2.0
 * ----------------------------------------------------------------------------
 *
 * created on 05.03.2012 by jkonopka
 */
package de.sql.toolkit.generator;

import java.io.File;

import de.sql.toolkit.model.Column;
import de.sql.toolkit.model.Table;

/**
 * @author jkonopka
 * 
 */
public class TableCreateScriptColumnGenerator extends AbstractGenerator {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7324188928881862197L;

	/**
	 * @param table
	 * @param dstPath
	 */
	public TableCreateScriptColumnGenerator(Table table, File dstPath) {
		super(table, dstPath);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see de.sql.toolkit.generator.IGenerator#generate()
	 */
	@Override
	public String generate() throws Exception {
		final StringBuilder sb = new StringBuilder();
		for (final Column column : getTable().getColumns()) {
			sb.append("\n\t");
			sb.append(column.getName());
			sb.append(" ");
			sb.append(column.getType());
			sb.append(" ");
			sb.append((column.getNullable() ? "" : "not null"));
			sb.append(" , ");
		}
		sb.delete(sb.lastIndexOf(" , "), sb.length());
		return sb.toString();
	}

}
